package com.lagou.homework.stage01.module3;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

public class Task3 {
    public static void main(String[] args) {
        String str = "123,456,789,123,456";
        HashMap<String,Integer> hm = new HashMap<>();

        int a;
        String[] strArr = str.split(",");
        for(int i = 0;i<strArr.length;i++){
            if(hm.containsKey(strArr[i])){
                a=hm.get(strArr[i]);
                hm.put(strArr[i],a+1);
            }else{
                hm.put(strArr[i],1);
            }
        }

        Iterator it = hm.entrySet().iterator();
        while(it.hasNext()){
            Map.Entry pairs = (Map.Entry)it.next();
            System.out.println("字符串 "+pairs.getKey() + " 的出现次数为： " + pairs.getValue());
        }

    }
}
